package main

import (
	"fmt"
	"html/template"
	"net/http"
)

type Address struct {
	City     string
	Province string
}
type UserInfo struct {
	Name    string
	Sex     string
	Age     int
	Address Address
}

func login(w http.ResponseWriter, r *http.Request) {
	method := r.Method
	if method == "GET" {
		t, err := template.ParseFiles("./index.html")
		if err != nil {
			fmt.Fprintf(w, "load login.html falied")
			return
		}

		user := UserInfo{
			Name: "Mary",
			Sex:  "男",
			Age:  18,
			Address: Address{
				City:     "北京",
				Province: "北京市",
			},
		}
		// m := make(map[string]interface{})
		// m["Name"] = "Mary"
		// m["Sex"] = "female"
		// m["Age"] = 18
		// t.Execute(w, m)
		t.Execute(w, user)
	}
}
func main() {
	http.HandleFunc("/login", login)
	err := http.ListenAndServe(":9090", nil)
	if err != nil {
		fmt.Printf("listen server falied,err :%v\n", err)
		return
	}
}
